package com.ys.peony.ui.activity;

import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.Request;
import com.bumptech.glide.request.animation.GlideAnimation;
import com.bumptech.glide.request.target.SizeReadyCallback;
import com.bumptech.glide.request.target.Target;
import com.shizhefei.view.largeimage.LargeImageView;
import com.shizhefei.view.largeimage.factory.FileBitmapDecoderFactory;
import com.ys.peony.R;
import com.ys.peony.base.BaseActivity;

import java.io.File;

import butterknife.BindView;

public class ShowImageActivity extends BaseActivity implements View.OnClickListener{
    public final static String IMG_URL = "img_url";

    @BindView(R.id.imageView)
    LargeImageView largeImageView;
    @Override
    protected int getContentResId() {
        return R.layout.activity_show_image;
    }

    @Override
    protected void initView() {
        largeImageView.setOnClickListener(this);
        if(getIntent() != null && getIntent().getExtras() != null) {
            Bundle bundle = getIntent().getExtras();
            String imgUrl = bundle.getString(IMG_URL);
            if(!TextUtils.isEmpty(imgUrl)) {
                Glide.with(this).load(imgUrl).downloadOnly(new Target<File>() {
                    @Override
                    public void onLoadStarted(Drawable placeholder) {

                    }

                    @Override
                    public void onLoadFailed(Exception e, Drawable errorDrawable) {

                    }

                    @Override
                    public void onResourceReady(File resource, GlideAnimation<? super File> glideAnimation) {
                        largeImageView.setImage(new FileBitmapDecoderFactory(resource));
                    }

                    @Override
                    public void onLoadCleared(Drawable placeholder) {

                    }

                    @Override
                    public void getSize(SizeReadyCallback cb) {
                        cb.onSizeReady(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL);
                    }

                    @Override
                    public void setRequest(Request request) {

                    }

                    @Override
                    public Request getRequest() {
                        return null;
                    }

                    @Override
                    public void onStart() {

                    }

                    @Override
                    public void onStop() {

                    }

                    @Override
                    public void onDestroy() {

                    }
                });
            }
        }

    }

    @Override
    public void onClick(View view) {
        finish();
    }
}
